<template>
  <div class="employees-container">
    <div class="app-container">
      <el-card>
        <!-- 放置表单 -->
        <el-form
          ref="userForm"
          label-width="120px"
          :model="userInfo"
          :rules="rules"
          style="margin-left: 120px; margin-top: 30px"
        >
          <el-form-item label="姓名:" prop="username">
            <el-input v-model="userInfo.username" style="width: 300px" />
          </el-form-item>

          <el-form-item label="手机">
            <el-input v-model="userInfo.mobile" disabled style="width: 300px" />
          </el-form-item>

          <el-form-item label="入职时间">
            <el-date-picker
              v-model="userInfo.timeOfEntry"
              type="date"
              value-format="yyyy-MM-dd"
            />
          </el-form-item>

          <el-form-item label="员工头像">
            <!-- <upload-img :url="userInfo.staffPhoto" @get-url="getUrl" /> -->
            <upload-img v-model="userInfo.staffPhoto" />
          </el-form-item>

          <!-- 保存个人信息 -->
          <el-row class="inline-info" type="flex" justify="center">
            <el-col :span="12">
              <el-button type="primary" @click="confirm">保存更新</el-button>
              <el-button @click="$router.back()">返回</el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script>
// 数据回显
// 1. 准备接口
// 2. 路由方法获取id
// 3. 发送接口请求
// 4. 绑定的表单中
import { getUserDetailById, saveUserDetailById } from '@/api/user'
export default {
  data () {
    return {
      userInfo: {},
      rules: {}
    }
  },
  mounted () {
    this.fetchDetail()
  },
  methods: {
    async fetchDetail () {
      const res = await getUserDetailById(this.$route.query.id)
      this.userInfo = res.data
    },
    async confirm () {
      // 调用更新接口
      await saveUserDetailById(this.userInfo)
      this.$message.success('修改成功')
    }
    // getUrl (imgUrl) {
    //   this.userInfo.staffPhoto = imgUrl
    // }
  }
}
</script>
